package main

import (
	"gopkg.in/mgo.v2/bson"
	"log"
	"mycode_project/loyocloud-infrastructure/services/mongo"
)

type Order struct {
	Id bson.ObjectId `bson:"_id" json:"id"`
}

//database,collection,session
func (order *Order) GetMgoInfo() (string,string,string){
	return "static","eth-usdt_cal_result","master"
}

func (order *Order) GetId() bson.ObjectId{
	return order.Id
}

func main(){

	/*defer func() {
		fmt.Println("打印前")
	}()

	defer func() {
		if err:=recover();err!=nil{
			fmt.Println("打印中")
		}
	}()

	defer func() {
		fmt.Println("打印后")
	}()
   fmt.Println("'0'",byte('0'))

	str := "123"
	s0 := str
	by := []byte(str)
	fmt.Println(by)
	n:=0
	for _, ch := range []byte(str) {
		fmt.Println("ch",ch)
		ch -= '0'
		fmt.Println("ch",ch)
		if ch > 9 {
			//return 0, &NumError{fnAtoi, s0, ErrSyntax}
		}
		n = n*10 + int(ch)
	}
	if s0[0] == '-' {
		n = -n
	}*/
	//panic("打印1")

	err:=mongo.Startup("master",
		"localhost:27017",
		"static",
		"",
		"")
log.Println("err:",err)
	result:=make([]*Order,0)

	o:=mongo.NewOrm()
	pip:=o.Pipe(new(Order))
	pip.Do(mongo.Match,bson.M{"_id":bson.M{"$gt":bson.ObjectIdHex("5d29a149396fa66d31290d9c")}})
	err=pip.Limit(1).All(&result)
	log.Println("111:",err,"len result:",len(result))

	if err==nil{
		log.Println("id:",result[0].Id)
	}
}
